//
//  NewsHeaderView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/8.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class NewsHeaderView: UIView {
    var systemBtn:UIButton = {
        let btn = UIButton.init(type: .custom)
        btn.setTitle("系统消息", for: .normal)
        btn.frame = FRAME_CGFloat(0, 0, SCREEN_WIDTH / 3, 44)
        btn.backgroundColor = UIColor.clear
        btn.setTitleColor(RGB_Same(53), for: .normal)
        btn.titleLabel?.font = Font_Semibold(17)
        btn.addTarget(self, action: #selector(dateAction), for: .touchUpInside)
        btn.tag = 11
        return btn
    }()
    var activityBtn:UIButton = {
        let btn = UIButton.init(type: .custom)
        btn.setTitle("活动消息", for: .normal)
        btn.frame = FRAME_CGFloat(SCREEN_WIDTH / 3, 0, SCREEN_WIDTH / 3, 44)
        btn.backgroundColor = UIColor.clear
        btn.setTitleColor(RGB_Same(53), for: .normal)
        btn.titleLabel?.font = Font_Medium(17)
        btn.addTarget(self, action: #selector(dateAction), for: .touchUpInside)
        btn.tag = 12
        return btn
    }()
    var commentBtn:UIButton = {
        let btn = UIButton.init(type: .custom)
        btn.setTitle("评论消息", for: .normal)
        btn.frame = FRAME_CGFloat(SCREEN_WIDTH * 2 / 3, 0, SCREEN_WIDTH / 3, 44)
        btn.backgroundColor = UIColor.clear
        btn.setTitleColor(RGB_Same(53), for: .normal)
        btn.titleLabel?.font = Font_Medium(17)
        btn.addTarget(self, action: #selector(dateAction), for: .touchUpInside)
        btn.tag = 13
        return btn
    }()
    
    var systemView:UIView = {
        let imageView = UIView(frame: CGRect(x:SCREEN_WIDTH / 6 - 8, y:42, width:16, height:3))
        imageView.backgroundColor = RGB_Same(53)
        return imageView
    }()
    var activityView:UIView = {
        let imageView = UIView(frame: CGRect(x:SCREEN_WIDTH * 3 / 6 - 8, y:42, width:16, height:3))
        imageView.backgroundColor = UIColor.clear
        return imageView
    }()
    var commentView:UIView = {
        let imageView = UIView(frame: CGRect(x:SCREEN_WIDTH * 5 / 6 - 8, y:42, width:16, height:3))
        imageView.backgroundColor = UIColor.clear
        return imageView
    }()
    
    var dateBlock:((_ num:Int) -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.backgroundColor = RGB_Same(243)
        self.isUserInteractionEnabled = true
        
        self.addSubview(self.systemView)
        self.addSubview(self.activityView)
        self.addSubview(self.commentView)
        
        self.addSubview(self.systemBtn)
        self.addSubview(self.activityBtn)
        self.addSubview(self.commentBtn)
        
        systemChangeColor()
        
    }
    
    @objc func dateAction(btn:UIButton) {
        dateBlock?(btn.tag)
        switch btn.tag {
        case 11:
            systemChangeColor()
        case 12:
            activityChangeColor()
        case 13:
            commentChangeColor()
        default:
            return
        }
    }
    
    func systemChangeColor() {
        UIView.animate(withDuration: 0.3) {
            self.systemBtn.titleLabel?.font = Font_Semibold(17)
            self.activityBtn.titleLabel?.font = Font_Medium(17)
            self.commentBtn.titleLabel?.font = Font_Medium(17)
            self.systemView.backgroundColor = RGB_Same(53)
            self.activityView.backgroundColor = .clear
            self.commentView.backgroundColor = .clear
        }
    }
    func activityChangeColor() {
        UIView.animate(withDuration: 0.3) {
            self.systemBtn.titleLabel?.font = Font_Medium(17)
            self.activityBtn.titleLabel?.font = Font_Semibold(17)
            self.commentBtn.titleLabel?.font = Font_Medium(17)
            self.systemView.backgroundColor = .clear
            self.activityView.backgroundColor = RGB_Same(53)
            self.commentView.backgroundColor = .clear
        }
    }
    func commentChangeColor() {
        UIView.animate(withDuration: 0.3) {
            self.systemBtn.titleLabel?.font = Font_Medium(17)
            self.activityBtn.titleLabel?.font = Font_Medium(17)
            self.commentBtn.titleLabel?.font = Font_Semibold(17)
            self.systemView.backgroundColor = .clear
            self.activityView.backgroundColor = .clear
            self.commentView.backgroundColor = RGB_Same(53)
        }
    }

}
